#ifndef PHONONOUTPUT_H
#define PHONONOUTPUT_H

#include <math.h>
#include <QObject>
#include <QMainWindow>
#include <QIODevice>
#include <QTimer>
#include <QPushButton>
#include <QLabel>
#include <QComboBox>
#include <QByteArray>
#include <QSlider>
#include <QSpinBox>
#include <QAudioOutput>
#include <QHBoxLayout>
#include <QVBoxLayout>
#include <QDial>
#include <QBuffer>
#include "generator.h"
#include <phonon/AudioOutput>
#include <phonon/MediaObject>
#include <phonon/Path>
#include <phonon/VolumeSlider>
#include <phonon/AudioOutputDevice>
#include <phonon/BackendCapabilities>
#include <phonon/MediaSource>
#include <phonon/AudioDataOutput>
#include <QList>


class PhononOutput : public QMainWindow
{
    Q_OBJECT
public:
    int ToneFrequencyHz;
    QSlider* slider;
    QSpinBox* slider_value;
    QHBoxLayout* Hbox;
    QHBoxLayout* Hbox_buttons;
    QLabel* comboLabel;

    PhononOutput();
    ~PhononOutput();


private:
    void initializeWindow();
    void initializeAudio();
    void createAudioOutput();

private:
    QTimer*          m_pullTimer;
    QPushButton*     startstopbutton;
    QComboBox*       m_deviceBox;

    QAudioDeviceInfo m_device;
    Generator*       m_generator;
    QAudioOutput*    m_audioOutput;
    Phonon::AudioOutput* p_audiooutput; // phonon audio object
    Phonon::MediaObject* p_m_object;    // phonon medua object
    Phonon::Path*        p_path;        // phonon path
    Phonon::VolumeSlider* volume_slider;
    Phonon::MediaSource p_m_source;
    QList<Phonon::AudioOutputDevice> audioOutputDevices;
    Phonon::AudioOutputDevice* p_device;
    Phonon::AudioDataOutput* p_ado;

    QPushButton* IncreaseVolume;
    QPushButton* DecreaseVolume;
    QVBoxLayout* VLayout;
    QDial* volume_dial;
    QDial* volume_db_dial;



    QIODevice*       m_output; // not owned
    QAudioFormat     m_format;

    bool             m_pullMode;
    QByteArray       m_buffer;

    static const QString PushModeLabel;
    static const QString PullModeLabel;
    static const QString SuspendLabel;
    static const QString ResumeLabel;

private slots:
    void notified();
    void pullTimerExpired();
    void update_frequency();
    void set_p_device(int i);
    void warn_state(Phonon::State old_state, Phonon::State new_state);
    void start_stop_sound_phonon();
    void increase_db();
    void increase_db(int i);
    void decrease_db();
    void decrease_db(int i);
};

#endif // PHONONOUTPUT_H
